import Vue from 'vue'
import Router from 'vue-router'
import index from '@/page/index'
import login from '@/page/login'

Vue.use(Router)

const router = new Router({
  // mode: 'history',
  routes: [
    {
      path: '*',
      redirect: '/index'
    },
    {
      path: '/login',
      name: 'login',
      component: login
    },
    {
      path: '/index',
      name: 'index',
      component: index,
      meta: {
        requireAuth: true
      }
    },
  ]
})

/* 进入首页前判断是否登陆过、如果没有则跳转到登陆界面 */
// router.beforeEach((to, from, next) => {
//   if (to.path === '/login') {
//     next();
//   } else {
//     const token = localStorage.getItem("Authorization");
//     if (token === null || token === '') {
//       next('/login');
//     } else {
//       next();
//     }
//   }
// })

export default router;
